import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3;

/**
 * SettingsMenu Class
 * Settings options, reset scores, turn music on/off, turn sound on/off, and turn help on/off
 * 
 * @author Zong Xiong
 */
public class SettingsMenu implements MenuType{	

/***************************************************
 * Constants
 ***************************************************/

	// number of buttons in the menu
	private final int NUM_BUTTONS = 4;
	// strings for on and off text
	private String ON_STR = " on", OFF_STR = " off";
	
/***************************************************
 * Fields
 ***************************************************/
	
	// stores parent menu
	MenuType previousMenu;
	// stores selection of player
	int selection = 0;
	// stores buttons in the menu
	private GameObject []buttons;
	// stores strings for the menu options
	private String []titles;
	
/***************************************************
 * Public Methods
 ***************************************************/
	
	/**
	 * Default Constructor
	 * creates menu with parent menu
	 * 
	 * @param oldMenu, parent menu
	 */
	public SettingsMenu(MenuType oldMenu) {
		// stores parent menu
		previousMenu = oldMenu;

		// creates buttons and titles and loads them
		buttons = new GameObject[NUM_BUTTONS];
		titles = new String[NUM_BUTTONS];
		for (int i = 0; i < NUM_BUTTONS; i++) {
			buttons[i] = new GameObject(40, 380 - i * 100, 240, 80);
		}
		titles[0] = " Reset Scores";
		titles[1] = "Turn Music";
		titles[2] = "Turn Sound";
		titles[3] = "Turn Help";
	}

	/** {@inheritDoc} */
	@Override
	public void draw(SpriteBatch batch, TextureRegion inactiveButton,
			TextureRegion activeButton, TextureRegion textBar, TextureRegion grayBar, 
			BitmapFont menuFont, BitmapFont textFont) {
		// for a the buttons we run through and check if it is selected, if so we print the activeButton texture
		// if not we print inactiveButton texture
		for (int i = 0; i < NUM_BUTTONS; i++) {
			if (i==selection-1) {
				menuFont.setColor(Color.WHITE);
				batch.draw(activeButton, buttons[i].getX() + 240, buttons[i].getY(), 0, 0, 80, 240, 1, 1, 90);
				menuFont.draw(batch, titles[i], buttons[i].getX() + 20, buttons[i].getY() + 55);
				if (i == 0) {
					batch.draw(textBar, 0, 0, 165, 44);
					textFont.setColor(Color.BLACK);
					textFont.draw(batch, "Reset all Scores", 10, 30);
				}
				else if (i == 1) {
					batch.draw(textBar, 0, 0, 185, 44);
					textFont.setColor(Color.BLACK);
					textFont.draw(batch, "Turn Music On/Off", 10, 30);
				}
				else if (i == 2) {
					batch.draw(textBar, 0, 0, 190, 44);
					textFont.setColor(Color.BLACK);
					textFont.draw(batch, "Turn Sound On/Off",10, 30);
				}
				else if (i == 3) {
					batch.draw(textBar, 0, 0, 170, 44);
					textFont.setColor(Color.BLACK);
					textFont.draw(batch, "Turn Help On/Off", 10, 30);
				}
			}
			else {
				menuFont.setColor(Color.WHITE);
				batch.draw(inactiveButton, buttons[i].getX() + 240, buttons[i].getY(), 0, 0, 80, 240, 1, 1, 90);
				menuFont.draw(batch, titles[i], buttons[i].getX() + 20, buttons[i].getY() + 55);
			}
		}
		
	}

	/** {@inheritDoc} */
	@Override
	public MenuType getPreviousMenu() {
		// TODO Auto-generated method stub
		return previousMenu;
	}

	/** {@inheritDoc} */
	@Override
	public MenuType getMenuOption(Vector3 pointer) {
		// if selection and button pressed match, we create the sub menu with this as its parent
		if (selection == 1 &&buttons[0].contains(pointer)) {
			// reset scoreboards
		}
		else if (selection == 2 &&buttons[1].contains(pointer)) {
			// turn music on/off
		}
		else if (selection == 3 &&buttons[2].contains(pointer)) {
			// turn sound on/off
		}
		else if (selection == 4 &&buttons[3].contains(pointer)) {
			// turn help on/off
		}
		
		// else we check which button was pressed and update selection
		for (int i=0; i<NUM_BUTTONS; i++) {
			if (buttons[i].contains(pointer)) {
				selection = i+1;
			}
		}
		return null;
	}

	/** {@inheritDoc} */
	@Override
	public void setVisible(boolean visibility) {
		// currently not used, but planned for use of animations between menus
		
	}

	/** {@inheritDoc} */
	@Override
	public boolean isVisible() {
		// currently not used, but planned for use of animations between menus
		return false;
	}

}
